{% extends "_layout.html" %}
{% import "component/forms.njk" as forms %}

{# 样式代码 #}
{% block style %}
<link href="/css/plugins/iCheck/custom.css" rel="stylesheet">
{% endblock %}

{# bodyd代码#}
{% block body %}
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>添加定制类型</h5>

                </div>
                <div class="ibox-content">
                    <form class="form-horizontal m-t from" id="form" action="/custom/category/edit" method="post" data-href="/custom/category">
                    	{{ forms.hidden('id', data.id) }}

                        <div class="form-group">
                            <label class="col-sm-2 control-label">类型</label>
                            <div class="col-sm-8">
                                <select class="form-control m-b" name="type">
                                    <option value=""></option>
                                    <option value="1" {{ 'selected' if data.type == 1 }}>私人定制</option>
                                    <option value="2" {{ 'selected' if data.type == 2 }}>企业定制</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">上级分类</label>
                            <div class="col-sm-8">
                                <select class="form-control m-b" name="parentId">
                                {%for item in parent%}
                                {%if item.id != data.id%}
                                <option value="{{item.id}}" {{ 'selected' if data.parent.id == item.id }}>{{item.name}}</option>
                                {%endif%}
                                {% endfor %}
                                </select>
                            </div>
                        </div>

						{{ forms.text('名称', 'name', data.name, '请输入名称', 'required') }}
                        {{ forms.images(
                        label = '图片',
                            fileList = [{
                                name: 'image',
                                value: data.image,
                                url: ctx.helper.showImage(data.image, 160, 160, 'fixed'),
                                text: 'PC'
                            }]
                        )}}
                        {{ forms.text('排序', 'sort', data.sort, '请输入排序', 'required') }}
						{{ forms.textarea('描述', 'info', data.info, '请输入描述', 'required') }}
						{{ forms.textarea('备注', 'remark', data.remark, '请输入备注', 'required') }}

                        {{ forms.submit() }}

                    </form>
                </div>
            </div>
        </div>

    </div>
{% endblock %}

{#js代码#}
{% block js %}
<script>
    $(function () {
        var e = "";
        $("#form").validate({
            rules: {
                parentId: "required",
                status: "required",
                name: "required",
                image: "required",
                info: "required",
                remark: "required",
                createTime: "required",
                sort: "required",
            },
            messages: {
                parentId: {
                    required: e + "请输入parentId"
                },
                name: {
                    required: e + "请输入名称"
                },
                image: {
                    required: e + "请输入图片"
                },
                info: {
                    required: e + "请输入描述"
                },
                remark: {
                    required: e + "请输入备注"
                },
                sort: {
                    required: e + "请输入sort"
                }
            },
            submitHandler: function() {
              asyncSubmitForm($("#form"));
            }
        });

    });
</script>

{% endblock %}